package com.loong.ems.domain.vo.resp;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
/**
 * @author 龙勇-229970722
 * @date 2025-01-02 8:52
 * @description: Result
 */

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Result<T> implements Serializable {
     private static final long serialVersionUID = 7735505903525411467L;

    // 成功值,默认为1
    private static final int SUCCESS_CODE = 200;
    // 失败值,默认为0
    private static final int ERROR_CODE = 0;

    //状态码
    private int code;
    //消息
    private String message;
    //返回数据
    private T data;

    private Result(int code){
        this.code = code;
    }
    private Result(int code, T data){
        this.code = code;
        this.data = data;
    }
    private Result(int code, String message){
        this.code = code;
        this.message = message;
    }
    private Result(int code, String message, T data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> Result<T> success(){
        return new Result<T>(SUCCESS_CODE,"success");
    }
    public static <T> Result<T> success(String message){
        return new Result<T>(SUCCESS_CODE,message);
    }
    public static <T> Result<T> success(T data){
        return new Result<T>(SUCCESS_CODE,ResponseCode.SUCCESS.getMessage(),data);
    }
    public static <T> Result<T> success(String message, T data){
        return new Result<T>(SUCCESS_CODE,message,data);
    }

    public static <T> Result<T> error(){
        return new Result<T>(ERROR_CODE,"error");
    }
    public static <T> Result<T> error(String message){
        return new Result<T>(ERROR_CODE,message);
    }
    public static <T> Result<T> error(int code, String message){
        return new Result<T>(code,message);
    }
    public static <T> Result<T> error(ResponseCode res){
        return new Result<T>(res.getCode(),res.getMessage());
    }

    public int getCode(){
        return code;
    }
    public String getMessage(){
        return message;
    }
    public T getData(){
        return data;
    }
}
